package com.sinoeyes.controller.flowdata;

import com.sinoeyes.common.core.controller.BaseController;
import com.sinoeyes.common.core.page.RestPageResult;
import com.sinoeyes.common.result.RCode;
import com.sinoeyes.common.result.Result;
import com.sinoeyes.common.utils.bean.ObjectUtils;
import com.sinoeyes.flowdata.filter.FlowPurchaseDataFilter;
import com.sinoeyes.flowdata.service.IFlowPurchaseDataService;
import com.sinoeyes.flowdata.vo.FlowPurchaseDatasVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 标准采购流向Controller
 * 
 * @author steven.zhang
 * @date 2019-10-10
 */
@Api(value = "FlowData Purchase API", tags = {"标准采购流向接口"})
@RestController
@RequestMapping("/flowdata/purchase")
public class IFlowPurchaseDatasController extends BaseController{

    @Autowired
    private IFlowPurchaseDataService flowPurchaseDatasService;

    @ResponseBody
    @ApiOperation("获取单条流向数据信息")
    @ApiImplicitParam(name = "id", value = "流向数据ID", required = true, dataType = "String", paramType = "path")
    @GetMapping("/getFlowPurchaseDatasById/{id}")
    public Result<FlowPurchaseDatasVo> getFlowPurchaseDatasById(@PathVariable String id) {
        FlowPurchaseDatasVo flowPurchaseDatasVo = flowPurchaseDatasService.selectFlowPurchaseDatasById(id);
        if (ObjectUtils.isNotEmpty(flowPurchaseDatasVo)) {
            return Result.success(flowPurchaseDatasVo);
        }
        return Result.failure(RCode.NO_QUERY);
    }

    @ResponseBody
    @ApiOperation("获取流向数据列表")
    @PostMapping("/getFlowPurchaseDatasByFilter")
    public Result<RestPageResult<FlowPurchaseDatasVo>> getFlowSalesDatasByFilter(@RequestBody(required = false) FlowPurchaseDataFilter flowPurchaseDataFilter) {
        RestPageResult<FlowPurchaseDatasVo> pageReuslt = flowPurchaseDatasService.selectFlowPurchaseDatasByFilter(flowPurchaseDataFilter);
        if (pageReuslt != null) {
            return Result.success(pageReuslt);
        }
        return Result.failure(RCode.NO_QUERY);
    }
}
